package com.khotyn.heresy.service;

import com.khotyn.heresy.bean.PictureAlbum;
import com.khotyn.heresy.dao.AlbumDAO;
import com.khotyn.heresy.dao.PictureAlbumDAO;

/**
 * 设置相册封面服务类
 * 
 * @author 黄挺
 * 
 */
public class SetAsEnvelopService {
	private AlbumDAO albumDAO;
	private PictureAlbumDAO pictureAlbumDAO;

	/**
	 * 设置相册服务函数
	 * 
	 * @param pictureID 图片ID
	 * @param albumID 相册ID
	 * @param userID 用户ID
	 * @param requestUrl 请求URL
	 * @throws Exception 图片相册不匹配
	 */
	public void doService(String pictureID, Integer albumID, Integer userID) throws Exception {

		doDBOperate(pictureID, albumID);
	}

	/**
	 * 设置相册数据库操作
	 * 
	 * @param pictureAlbum 图片相册关联Bean
	 * @param browseLog 日志Bean
	 * @throws Exception 图片相册不匹配
	 */
	public void doDBOperate(String pictureID, Integer albumID) throws Exception {
		// 图片不属于该相册
		PictureAlbum pictureAlbum = new PictureAlbum();
		pictureAlbum.setAlbumID(albumID);
		pictureAlbum.getPictureBrief().setPictureID(pictureID);

		if (pictureAlbumDAO.selectPictureAlbumByPK(pictureAlbum) == null) {
			throw new Exception("该图片不属于该相册");
		}

		albumDAO.updateEnvelopPicId(albumID, pictureID);
	};

	public void setAlbumDAO(AlbumDAO albumDAO) {
		this.albumDAO = albumDAO;
	}

	public void setPictureAlbumDAO(PictureAlbumDAO pictureAlbumDAO) {
		this.pictureAlbumDAO = pictureAlbumDAO;
	}
}
